<?php
/**
 * jishupu-cms
 * @Author:技术铺<jishupu@qq.com>
 * @Date: 2021/11/11
 */

namespace App\Http\Resources;

/**
 * 导航模块资源
 * Class NavigationResource
 * @package App\Http\Resources
 */
class NavigationResource extends BaseResource
{
    /**
     * @param \Illuminate\Http\Request $request
     * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
     */
    public function toArray($request)
    {
        $info_category = [];
        if ($this->infoCategory) {
            $info_category = ['id' => $this->infoCategory->id, 'name' => $this->infoCategory->name];
        }
        return $this->filterFields([
            'id' => $this->id,
            'type' => $this->type,
            'info_category_id' => $this->info_category_id,
            'parent_id' => $this->parent_id,
            'name' => $this->name,
            'id_name' => $this->id_name,
            'href' => $this->href,
            'href_target' => $this->href_target,
            'rel' => $this->rel,
            'sort' => $this->sort,
            'status' => $this->status,
            'created_at' => $this->created_at ? $this->created_at->format('Y-m-d H:i:s') : "",
            'updated_at' => $this->updated_at ? $this->updated_at->format('Y-m-d H:i:s') : "",
            'info_category' => $info_category
        ]);
    }
}
